VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsEmployerExists"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit

Public Function EmployerExists(ByVal sEmployerPaye As String, ByRef nEmpID As String) As Boolean

    Dim cnEmployerExists As ADODB.Connection
    Dim rsCount As ADODB.Recordset
    Dim rsEmployerExists As ADODB.Recordset
    Dim cmd1 As ADODB.Command
    Dim cmd2 As ADODB.Command
    
   
    
    Set cnEmployerExists = New ADODB.Connection
    
    Set cmd1 = New ADODB.Command
    Set cmd2 = New ADODB.Command
    Set rsCount = New ADODB.Recordset
    Set rsEmployerExists = New ADODB.Recordset
    Dim SQL1 As String
    Dim SQL2 As String
    Dim nNumberOfEmployersExist As String
        
    With cnEmployerExists
        .ConnectionString = GetConnectionString() 'Johann (20090625): Centralised code for connection string added
        .Open
    End With
    
    'Count how many records exist for the same fund number
    'SQL1 = "select Count(*) NumberOfEmployerExists from dir_employers where paye_ref_no = " & sEmployerPaye
    'Tina... 30/09/2003 - add because it happened that through Interface there was a record in
    'dir_employers, but not in dir_contact_details
    SQL1 = "select Count(*) NumberOfEmployerExists from dir_employers e, dir_contact_details c Where e.paye_ref_no = " & sEmployerPaye
    SQL1 = SQL1 & " and e.emp_id = c.emp_id"
    Set cmd1 = New ADODB.Command
    Set cmd1.ActiveConnection = cnEmployerExists
    
    cmd1.CommandType = adCmdText
    cmd1.CommandText = SQL1
    
    Set rsCount = cmd1.Execute
    nNumberOfEmployersExist = rsCount.Fields("NumberOfEmployerExists").Value
    
    'Tina... 2003/09/23
    'If nNumberOfEmployersExist > 1 Then
    If nNumberOfEmployersExist >= 1 Then
        
        'Get the fund ID. This ID will be used to determine which one of the fund number details to update.
        SQL2 = "select emp_id from dir_employers where paye_ref_no = " & sEmployerPaye
        
        Set cmd2 = New ADODB.Command
        Set cmd2.ActiveConnection = cnEmployerExists
        
        cmd2.CommandType = adCmdText
        cmd2.CommandText = SQL2
        
        
        ' Perform the query
        Set rsEmployerExists = cmd2.Execute
        
        If Not rsEmployerExists.EOF Then
            EmployerExists = True
            nEmpID = rsEmployerExists.Fields("emp_id").Value
        Else
            EmployerExists = False
        End If
        
        'cleanup
        rsEmployerExists.Close
        Set rsEmployerExists = Nothing
        cnEmployerExists.Close
        Set cnEmployerExists = Nothing
        
    Else
        EmployerExists = False
    End If
    

    'clean up
    'rsCount.Close
    Set rsCount = Nothing
    
    
    

End Function

